package com.swk.version4.util;

/**
 * 
 * @author 慎伟康
 * 
 * @date 2018年1月13日 下午11:21:01
 * 
 * @Description
 *    页面解析帮助类
 */
public final class AnalyzeUtils {

	/**
	 * 为章节名中缺少“章”的章节添加“章”，方便阅读器解析章节列表
	 * @param chapterName
	 * @return
	 */
	public static String addZhang(String chapterName){
		//找到章节数与章节名的分割符，如" "、":"
		if(chapterName.contains(" ")){
			String[] temp = chapterName.split(" ");
			if(!chapterName.contains("第") && !chapterName.contains("章") && chapterName.contains("外卷")){
				chapterName = temp[0] + "章 " + temp[1];
				chapterName = chapterName.replace("外卷", "外卷第");
				
			}else if(!chapterName.contains("第") && !chapterName.contains("章")){
				chapterName = "第" + temp[0] + "章 " + temp[1];
				
			}else if(!chapterName.contains("章")){
				if(temp[1].contains("第")){
					chapterName = "第" + temp[0] + "章 " + temp[1];
				}else{
					chapterName = temp[0] + "章 " + temp[1];
				}
			}else if(!chapterName.contains("第")){
					chapterName = "第" + chapterName;
			}
			
		}else if(chapterName.contains(":")){
			String[] temp = chapterName.split(":");
			if(chapterName.contains("外卷")){
				chapterName = temp[0] + "章 " + temp[1];
				chapterName = chapterName.replace("外卷", "外卷第");
			}
		}else if(!chapterName.contains("章")){
			chapterName = "第0章" + chapterName;
		}
		return chapterName;
	}
}
